﻿using System;
using System.Windows.Forms;
using iSonar.iCarus.Interfaces;
using iSonar.iCarus.Gui.Dialogs;
using iSonar.iCarus.Core.DataTypes;
using Org.BouncyCastle.Asn1;
using System.IO;

namespace iSonar.iCarus.Gui.Controls {
  public partial class Asn1OidParametrizedViewCtrl : UserControl, IViewer {
    public Asn1OidParametrizedViewCtrl() {
      InitializeComponent();
    }

    private const string UrlForm = "http://www.oid-info.com/get/{0}";

    #region IViewer Members
    public void InitializeView(IViewee viewee) {
      try {
        Asn1Oid oid = viewee as Asn1Oid;
        byte[] der = oid.GetObject() as byte[];
        Asn1InputStream asn1Stream = new Asn1InputStream(new MemoryStream(der));
        DerObjectIdentifier derOid = asn1Stream.ReadObject() as DerObjectIdentifier;
        webBrowser_Asn1Oid.Navigate(string.Format(UrlForm, derOid.ToString()));
      } catch (Exception ex) {
        new AppError(ex).ShowDialog(this);
      }
    }
    #endregion
  }
}
